package com.edu.chat.web.covert;

import com.edu.chat.web.dto.FileDTO;
import com.edu.chat.web.dto.UploadFileDTO;
import com.edu.chat.web.model.CsFile;
import org.springframework.web.multipart.MultipartFile;

/**
 * @program: KQAIA
 * @description:
 * @author: 无恙
 * @create: 2025-03-17 16:33
 **/


public class FileCovert {

	public static UploadFileDTO covert(MultipartFile file,String categoryId,String libraryId){
		UploadFileDTO uploadFileDTO = new UploadFileDTO();
		uploadFileDTO.setCategoryId(categoryId);
		uploadFileDTO.setLibraryId(libraryId);
		uploadFileDTO.setMultipartFile(file);
		uploadFileDTO.setFileSize(String.valueOf(file.getSize()));
		uploadFileDTO.setFileType(file.getContentType());
		uploadFileDTO.setFileName(file.getOriginalFilename());
		return uploadFileDTO;
	}
	public static CsFile buildCsFile(UploadFileDTO file) {
		CsFile csFile = new CsFile();
		csFile.setFileType(file.getFileType());
		csFile.setFileUrl(file.getFilePath());
		csFile.setCategoryId(file.getCategoryId());
		csFile.setLibraryId(file.getLibraryId());
		csFile.setTitle(file.getFileName());
		csFile.setFileSize(file.getFileSize());
		csFile.setObjectName(file.getObjectName());
		return csFile;
	}


	public static FileDTO covert(CsFile csFile){
		FileDTO fileDTO = new FileDTO();
		fileDTO.setId(String.valueOf(csFile.getId()));
		fileDTO.setLibraryId(csFile.getLibraryId());
		fileDTO.setCategoryId(csFile.getCategoryId());
		fileDTO.setName(csFile.getTitle());
		fileDTO.setFileType(csFile.getFileType());
		fileDTO.setFileUrl(csFile.getFileUrl());
		fileDTO.setFileSize(csFile.getFileSize());
		return fileDTO;
	}
}
